import request from '@/utils/request'

interface ApiResponse<T = any> {
  code: number
  msg: string
  data: T
  count?: number
}

interface PaginationData<T> {
  list: T[]
  total: number
  page: number
  limit: number
}

// 合同相关API
export const contractApi = {
  // 获取合同列表
  getList: (params: any): Promise<ApiResponse<PaginationData<any>>> => {
    return request({
      url: '/api/user/contract/list',
      method: 'get',
      params,
    })
  },

  // 获取合同详情
  getDetail: (id: number): Promise<ApiResponse<any>> => {
    return request({
      url: `/api/user/contract/view/${id}`,
      method: 'get',
    })
  },

  // 新增合同
  add: (data: any): Promise<ApiResponse> => {
    return request({
      url: '/api/user/contract/add',
      method: 'post',
      data,
    })
  },

  // 编辑合同
  edit: (data: any): Promise<ApiResponse> => {
    return request({
      url: '/api/user/contract/edit',
      method: 'post',
      data,
    })
  },

  // 删除合同
  delete: (id: number): Promise<ApiResponse> => {
    return request({
      url: '/api/user/contract/del',
      method: 'delete',
      params: { id },
    })
  },
}

export default contractApi
